package com.gtxc.kotlinmvvm.utlis

import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonToken
import com.google.gson.stream.JsonWriter
import java.io.IOException

/**
 * FileName:StringAdapter
 * Author：Administrator
 * Date:2021 2021/9/27 18:42
 * Copyright (C), 2020-2021,成都拇音科技有限公司
 *
 *
 *
 *
 * Description: zwl
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
</desc></version></time></author> */
class StringAdapter : TypeAdapter<String?>() {
    @Throws(IOException::class)
    override fun write(out: JsonWriter, value: String?) {
        if (value == null) {
            out.value("")
            return
        }
        out.value(value)
    }

    @Throws(IOException::class)
    override fun read(reader: JsonReader): String? {
        if (reader.peek() == JsonToken.NULL) {
            reader.nextNull()
            return ""
        }
        return reader.nextString()
    }
}